package dao;

import java.sql.SQLException;
import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.Query;

import pojo.Produto;
import pojo.Venda;

public class DaoVenda implements Dao<Venda> {

	EntityManager em;
	
	public DaoVenda(EntityManager em) {
		super();
		this.em=em;
	}
	
	@Override
	public void gravar(Venda bean) throws SQLException {
		em.getTransaction().begin();
		em.persist(bean);
		em.getTransaction().commit();
	}

	@Override
	public Venda buscar(String valor) throws SQLException {
		Query q = em.createQuery("SELECT v FROM Venda v WHERE v.codigo = :id");
		q.setParameter("id", Long.parseLong(valor));
		return (Venda) q.getSingleResult();
	}

	

	@SuppressWarnings("unchecked")
	@Override
	public List<Venda> obterLista(Class<Venda> tipo) throws SQLException {
		Query q = em.createQuery("SELECT v FROM Venda v");
		return q.getResultList();
	}

	@Override
	public void atualizar(Venda entidade) throws SQLException {
		// TODO Auto-generated method stub
		
	}

}
